<?php 
require 'kernel/common.php';
if(!$Session->check_admin()) redirect('index.php');

if(isset($_POST['send_delete']) || isset($_POST['cancel_delete']))
{
    if(!$Session->csrf_check()) redirect('logout.php');
	if(isset($_POST['cancel_delete'])) redirect('utlisateur.php');
	
	if(isset($_POST['send_delete']))
	{
		if(!$id = retrieve('POST', 'id', true)) redirect('utilisateur.php?error=no_user_select');
		$db->sql_query("DELETE FROM immo_user WHERE id = '". $id ."'");
		$db->sql_query("DELETE FROM immo_user_agence WHERE user = '". $id ."'");
        $db->sql_query("DELETE FROM immo_groupe_user_link WHERE uid = '". $id ."'");
		
		SuccesAffiche($lang['Utilsiateur_supprime'], 'utilisateur.php');
		exit;
	}
}
else
{
	if(!$id = retrieve('GET', 'id', true)) redirect('utilisateur.php?error=no_user_select');
	else
	{
		$Sql = $db->sql_query("SELECT * FROM immo_user WHERE id ='". $id ."'");
		$Utilisateur = $db->sql_fetchobject($Sql);
		$template->set_filenames(array('utilisateur_supprime' => 'template/utilisateur_suppression.tpl'));
		$template->assign_vars(array(
		'V_ID'	=>	$id,
		'V_NOM'	=>	$Utilisateur->nom,
		'V_PRENOM'	=>	$Utilisateur->prenom,
		'V_IDENTIFIANT'	=>	$Utilisateur->identifiant,
        'V_TOKEN'   =>  $_SESSION['token'],
		'L_CONFIRMER_SUPPRESSION_UTILISATEUR'	=>	$lang['Confirmer_suppression_utilisateur'],
		'L_SUPPRIMER'	=>	$lang['Supprimer'],
		'L_ANNULER'	=>	$lang['Annuler'],
		'L_RETOUR'	=>	$lang['Retour'],
		));
		$template->display('utilisateur_supprime');
	}	
    require 'footer.php';
}
?>